package com.asa.ui.H;

import java.awt.EventQueue;
import java.util.Arrays;

import com.asa.ui.frame.AlgoVisHelper;


public class AlgoVisualizer {
	private static final int DELAY = 5;
	private static int blockSide = 80;
	private AlgoFrame frame;
	private GameData data;
	
	public AlgoVisualizer(final String filename){
		

		EventQueue.invokeLater(new Runnable() {//用java事件分发（开了个线程）的方法来创建对话框
			
			@Override
			public void run() {
				// TODO Auto-generated method stub
//				frame=new AlgoFrame("随机分钱开始问题模拟",screenWidth,screenHeight);
				
				data = new GameData(filename);
				int sceneWidth = data.getM()*blockSide;
				int sceneHeight = data.getN()*blockSide;
				frame = new AlgoFrame(data,"move the box solver", sceneWidth, sceneHeight);
				
				new Thread(new Runnable() {
					
					@Override
					public void run() {
						// TODO Auto-generated method stub
						runmiage();
					}

					
				}).start(); ;
				
			}
		});
		
		
	}
	//播放动画
	public void runmiage(){
		setData();
		if (data.solve()) {
			System.out.println("有解");
		}else {
			System.out.println("无解");

		}
	}
	private void setData() {
		// TODO Auto-generated method stub
		frame.render(data);
		AlgoVisHelper.pause(DELAY);
	}

}